import {
  supplierTotalData,
  supplier30DaysData,
  supplierTop100,
  supplierOrderSource,
} from "@/common/apis/supplier.js";

const state = {
  supplierTotalData: {
    sale_amount: "0",
    sale_cnt: "0",
    sale_service_amount: "0",
    sale_service_ant: "0",
  },
  supplier30DaysData: {},
  supplierTop100: [],
  supplierOrderSource: {
    merchant_order_cnt: 0,
    customer_order_cnt: 0,
  },
};

const getters = {};

const mutations = {
  setSupplierTotalData(state, data) {
    state.supplierTotalData = data;
  },
  setSupplier30DaysData(state, data) {
    state.supplier30DaysData = data;
  },
  setSupplierTop100(state, data) {
    state.supplierTop100 = data;
  },
  setSupplierOrderSource(state, data) {
    state.supplierOrderSource = data;
  },
};

const actions = {
  async fetchSupplierTotalData({ commit }) {
    const res = await supplierTotalData();
    commit("setSupplierTotalData", res);
  },
  async fetchSupplier30DaysData({ commit }) {
    const res = await supplier30DaysData();
    commit("setSupplier30DaysData", res);
  },
  async fetchSupplierTop100({ commit }) {
    const res = await supplierTop100();
    commit("setSupplierTop100", res);
  },
  async fetchSupplierOrderSource({ commit }) {
    const res = await supplierOrderSource();
    commit("setSupplierOrderSource", res);
  },
};

export default {
  state,
  getters,
  mutations,
  actions,
};
